package com.learn.learnsystem.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

// config/UserSecurityConfig.java
@Configuration
public class UserSecurityConfig {

    @Bean
    public UserDetailsService userDetailsService() {
        return username -> {
            // 实现根据用户名从数据库获取用户的逻辑
            // 示例：
            UserDetails user = User.builder()
                    .username("admin")
                    .password(passwordEncoder().encode("admin123"))
//                    .password("admin123")
//                    .roles("ADMIN")
                    .build();

            // 实际项目应从数据库查询
            return user;
        };
    }
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

}